package org.flynenu.ums.common.entity.core;

import org.flynenu.core.dao.session.SessionBuilder;
import org.flynenu.core.dao.session.SessionBuilderImpl;

public class DataSourceFactory {
	private static String hibernateConfFilePath="org/flynenu/ums/dao/script/hibernate.cfg.xml";
	
	private SessionBuilderImpl session = null;

	public static void setHibernateConfFilePath(String hibernateConfFilePath) {
		DataSourceFactory.hibernateConfFilePath = hibernateConfFilePath;
	}

	private static DataSourceFactory instance = null;
	
	public DataSourceFactory(){}

	public static SessionBuilder getSession(){
		if (instance != null) {
			return instance.session;
		}
		synchronized (DataSourceFactory.class) {
			if (instance != null){
				return instance.session;
			}

			instance = new DataSourceFactory();
			instance.session = new SessionBuilderImpl();
			instance.session.setXmlPath(hibernateConfFilePath);
		}
		return instance.session;
	}
}
